package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortListDemo2 {
    public static void main(String[] args) {
        List<Point> list = new ArrayList<>();
        list.add(new Point(3,4));
        list.add(new Point(31,16));
        list.add(new Point(61,13));
        list.add(new Point(12,9));
        list.add(new Point(88,66));
        list.add(new Point(99,44));
        list.add(new Point(82,77));
        list.add(new Point(66,66));
        System.out.println(list);
//        Comparator<Point> c = new Comparator<Point>() {
//            @Override
//            public int compare(Point o1, Point o2) {
//                int olen1 = o1.getX()*o1.getX()+o1.getY()*o1.getY();
//                int olen2 = o2.getX()*o2.getX()+o2.getY()*o2.getY();
//                //return olen1-olen2;//升序
//                return olen2-olen1;//反过来减就是降序(从大到小)
//            }
//        };


//        Collections.sort(list,new Comparator<Point>() {
//            @Override
//            public int compare(Point o1, Point o2) {
//                int olen1 = o1.getX()*o1.getX()+o1.getY()*o1.getY();
//                int olen2 = o2.getX()*o2.getX()+o2.getY()*o2.getY();
//                //return olen1-olen2;//升序
//                return olen2-olen1;//反过来减就是降序(从大到小)
//            }
//        });

        Collections.sort(list,(o1,o2)->
                o1.getX()*o1.getX()+o1.getY()*o1.getY()-
                o2.getX()*o2.getX()-o2.getY()*o2.getY()
                );
        System.out.println(list);
    }
}
